import * as vscode from "vscode";
import { rustImpl } from "./core";

const rustChannel = vscode.window.createOutputChannel('CatCoder', 'rust');

export const activate = async (context: vscode.ExtensionContext) => {

	const ra = vscode.extensions.getExtension("rust-lang.rust-analyzer");
	if (!ra) {
		vscode.window.showErrorMessage('Please install rust-analyzer plugin');
		return;
	}
	await ra.activate();
	if (!ra.isActive) {
		vscode.window.showErrorMessage('rust-analyzer plugin failed to activate');
		return;
	}

	const disposable = vscode.commands.registerCommand(
		"catcoder-vscode.rustGenerator",
		rustImpl(context, rustChannel)
	);

	context.subscriptions.push(disposable);
};

export const deactivate = () => {
	rustChannel.dispose();
};
